{* FILTERS *}

{literal}
<script language="javascript">
	var checkname="userid[]";
	
	function addfilter(field,value) {
		var forma = document.getElementById("ulist_form");
		var f = document.getElementById(field);
		f.value=value;		
		forma.submit();
	}
	function updateRequest(id,action) {
		if (countCheckedElements(checkname)>0) {
			var forma = document.getElementById("ulist_form");
			forma.op.value=action;
			forma.id.value=id;
			forma.submit();
		}
	}
	
	function updateUser(type,d) {
		showprogress();
		xajax_updateUser(xajax.getFormValues("ulist_form"),type);
		closeForm(d);
	}
	
	function sendUserMessage(event) {
		if (countCheckedElements(checkname)>0) {
			openMessage(event,getCheckedElements(checkname),'utu');
		}
	}

	function showForm(e,usrId,fop,d,f,val) {
		var coordinates = getDivPosition(e); 
		var el = document.getElementById(d);
		el.style.left=coordinates.x;
	    el.style.top=coordinates.y;
	
		var forma = document.getElementById("ulist_form");
	    forma.op.value=fop;
	    forma.id.value=usrId;
	    forma[f].value=val;
		el.style.display='';   
	 }

	
</script>
{/literal}
<script language="javascript">

	function deleteUser() {ldelim}
		if (confirm('{$lang.confirmdelete}')) {ldelim} 
			updateRequest('','remove')
		{rdelim}	
	{rdelim}
					
</script>

{include file="mp.tpl"}	

<center>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="3">
<b>{$lang.filterby}</b>
</td>
<tr>
<tr>
<td>
{$lang.status}
</td>
<td>
{$lang.group}
</td>
<td>
{$lang.team}
</td>
<tr>
<td VALIGN="top">
{if $statusid neq ""}
	<b>{$lang.$statusid}</b><br/>
	<span class="link" onclick="addfilter('fstatusid','')">{$lang.all}</span>	
{else}
	{foreach from=$statuslist item=strow}
		{eval var=$strow assign="stid"}
		<span class="link" onclick="addfilter('fstatusid','{$strow}')">{$lang.$stid}</span><br/>
	{/foreach}
{/if}
</td>
<td VALIGN="top">
{if $groupid neq ""}
	<b>{$lang.$groupid}</b><br/>
	<span class="link" onclick="addfilter('fgroupid','')">{$lang.all}</span>
{else}
	{foreach from=$grouplist item=ptrow}
		{eval var=$ptrow assign="grid"}
		{if $CURRENT_USER->groupid eq 'ADMIN' OR ($CURRENT_USER->groupid neq 'ADMIN' AND $grid neq 'ADMIN')}
			<span class="link" onclick="addfilter('fgroupid','{$ptrow}')">{$lang.$grid}</span><br/>
		{/if}
	{/foreach}
{/if}
</td>
<td VALIGN="top">
{if $teamid neq ""}
	<b>{$team->name}</b><br/>
	<span class="link" onclick="addfilter('fteamid','')">{$lang.all}</span>
{else}
	{foreach from=$teamlist item=urow}
		<span class="link" onclick="addfilter('fteamid','{$urow->id}')">{$urow->name}</span><br/>
	{/foreach}
{/if}
</td>
</tr>
</table>
</center>

<center>
<form method="post" id="ulist_form">
	<input type="hidden" name="flowid" id="flowid" value="{$flowid}">
	<input type="hidden" name="action" id="action" value="useradmin">
	<input type="hidden" name="fstatusid" id="fstatusid" value="{$statusid}">
	<input type="hidden" name="fgroupid" id="fgroupid" value="{$groupid}">	
	<input type="hidden" name="fteamid" id="fteamid" value="{$team->teamid}">
	<input type="hidden" name="op" id="op" value="">	
	<input type="hidden" name="id" id="id" value="">

	<table align="center" width="100%" border="0" cellpadding="0" cellspacing="0">
	
		<thead>
			<tr>
				<th>{$lang.userid}</th>
				<th>{$lang.group}</th>
				<th>{$lang.team}</th>
				<th>{$lang.status}</th>
				<th>&nbsp;</th>
				<th>
					<img src="images/arrowdown.png" alt="" width="18" height="18" class="link" onclick="checkAll('userid[]')">
					<img src="images/arrowup.png" alt="" width="18" height="18" class="link" onclick="uncheckAll('userid[]')">
				</th>
			</tr>
		</thead>
	
		{* TABLE BODY - DYNAMIC *}
		<tbody>
			{assign var="rowclass" value="uneven"}
			{foreach from=$list item=row}
				{eval var=$row->status assign="stid"}
				{eval var=$row->groupid assign="grid"}
				{if ($grid neq 'ADMIN' AND $CURRENT_USER->groupid neq 'ADMIN') OR $CURRENT_USER->groupid eq 'ADMIN'}
					<tr class="{$rowclass}" {if $stid neq 'ACTIVE'} style="font-style: italic" {/if}>
						<td><span class="link" onclick="openMessage(event,'{$row->userid}','utu')" title="{$lang.sendmp}">{$row->userid}</span></td>
						<td id="grouprow{$row->userid}">{$lang.$grid}</td>
						<td id="teamrow{$row->userid}">{$row->team->name}</td>				
						<td>{$lang.$stid}</td>
						<td>
							<span onclick="showForm(event,'{$row->userid}','chgrp','gedit','groupid','{$grid}')" class="link">{$lang.chgroup}</span>
							{if $CURRENT_USER->groupid eq 'ADMIN'}
								&nbsp;<span onclick="showForm(event,'{$row->userid}','chteam','tedit','teamid','{$row->teamid}')" class="link">{$lang.team}</span>
							{/if}
						</td>
						<td align="center">
							<input type="checkbox" class="txt" name="userid[]" id="userid[]" value="{$row->userid}" />
						</td> 
					</tr>
					{if $rowclass eq 'even'}
						{assign var="rowclass" value="uneven"}
					{else}
						{assign var="rowclass" value="even"}
					{/if}
				{/if}
			{/foreach}			
	
		</tbody>
	
		<tfoot>
			<tr>
				<th colspan="6">
					{include file="button.tpl" name=$lang.sendmp action="sendUserMessage(event)"}
					{include file="button.tpl" name=$lang.deactivate action="updateRequest('','deact')"}
					{include file="button.tpl" name=$lang.activate action="updateRequest('','act')"}
					{if $CURRENT_USER->groupid eq 'ADMIN'}
						{include file="button.tpl" name=$lang.resetpwd action="updateUser('reset','')"}
						{include file="button.tpl" name=$lang.remove action="deleteUser()"}
					{/if}
				</th>
			</tr>
		</tfoot>
	
	</table>

	{* GROUP *}
	<div name="gedit" id="gedit" style="display: none;" class="floatingform">
	{include file="close.tpl" element="gedit"}
		<table border="0" cellpadding="0" cellspacing="0">
			<tr>
				<td>{$lang.group}</td>
				<td>
					<select name="groupid" id="groupid">
						{foreach from=$grouplist item=ptrow}
							{eval var=$ptrow assign="grid"}
							{if $CURRENT_USER->groupid eq 'ADMIN' OR ($CURRENT_USER->groupid neq 'ADMIN' AND $grid neq 'ADMIN') }
								<option value="{$grid}">{$lang.$grid}</option>
							{/if}
						{/foreach}
					</select>			
				</td>
			</tr>
	   		<tr>
	   		<td>&nbsp;</td>
			<td align="right">
				{include file="button.tpl" name=$lang.ok action="updateUser('group','gedit')"}	
			</td>
		   	</tr>	
	   </table>	
	</div>

	{* TEAM *}
	<div name="tedit" id="tedit" style="display: none;" class="floatingform">
	{include file="close.tpl" element="tedit"}
	<table border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td>{$lang.team}</td>
			<td>
				<select name="teamid" id="teamid">
					{foreach from=$teamlist item=ptrow}
						<option value="{$ptrow->id}">{$ptrow->name}</option>
					{/foreach}
				</select>			
			</td>
		</tr>
   		<tr>
   		<td>&nbsp;</td>
		<td align="right">
			{include file="button.tpl" name=$lang.ok action="updateUser('team','tedit')"}	
		</td>
	   	</tr>	
   </table>		
	</div>
</form>
</center>
